const express = require('express')
const adminModel = require('./db/model/adminModel')
const app = express()
const path = require('path')
//body请求数据需要两个中间件
app.use(express.urlencoded())
app.use(express.json())

require('./db')
//引入数据库
require('./db/model/adminModel')

//引入外部路由
const addAdminRoutes = require('./routes/addAdmin')
const adminListRoutes = require('./routes/adminList')
const deleteAdminRoutes = require('./routes/deleteAdmin')
const loginRoutes = require('./routes/login')
const isLoginRoutes = require('./routes/isLogin')
const logoutRoutes = require('./routes/loginout')
const addAdvRoutes = require('./routes/addAdv')
const advListRoutes = require('./routes/advList')
const deleteAdvRoutes = require('./routes/deleteAdv')
const getUpDataRoutes = require('./routes/getUpData')
const UpDataAdvRoutes =require('./routes/UpDataAdv')

app.use(addAdminRoutes)
app.use(adminListRoutes)
app.use(deleteAdminRoutes)
app.use(loginRoutes)
app.use(isLoginRoutes)
app.use(logoutRoutes)
app.use(addAdvRoutes)
app.use(advListRoutes)
app.use(deleteAdvRoutes)
app.use(getUpDataRoutes)
app.use(UpDataAdvRoutes)
//暴露静态资源文件夹
app.use('/upload', express.static(path.resolve(__dirname, './upload')))

app.listen(8000, () => {
  console.log('服务器启动成功');
})